def find_set(x):
    if x != s[x]:
        s[x] = find_set(s[x])
    return s[x]

def merge_set(x, y):
    x = find_set(x)
    y = find_set(y)
    if x != y:
        s[x] = s[y]

n, m = map(int, input().split())
s = list(range(n + 1))

for i in range(m):
    op, x, y = map(int, input().split())
    if op == 1:
        merge_set(x, y)
    else:
        print('YES' if find_set(x) == find_set(y) else 'NO')